package cn.zw.msmp.common.util;

import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CommonUtils {

	private static final Logger log = LoggerFactory.getLogger(CommonUtils.class);
	
	/**
	 * 解码并转换请求参数
	 * @param reqParams
	 * @return
	 */
	public static Map<String, String> convertReqParams(String reqParams) {
		try {
			if(StringUtils.isNotEmpty(reqParams)){
				reqParams = URLDecoder.decode(reqParams, "UTF-8");
				String[] tmp = reqParams.split("&");
				Map<String, String> map = new HashMap<String, String>();
				for(String s1 : tmp) {
					String[] tmp2 = s1.split("=");
					if(tmp2.length == 2){
						String key = tmp2[0];
						String value = tmp2[1];
						map.put(key, value);
					}
				}
				return map;
			}
		} catch (Exception e) {
			log.error("decode content error,content="+reqParams, e);
		}
		return null;
	}
}
